package com.gymmsystem.GYMMSystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gymmsystem.GYMMSystem.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT * FROM users WHERE u_mobile = #{mobile}")
    User findByMobile(@Param("mobile") String mobile);

    @Update("UPDATE users SET u_nickname = #{nickname}, updated_at = NOW() WHERE user_id = #{userId}")
    int updateUserNickname(@Param("userId") Long userId, @Param("nickname") String nickname);

    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    User findUserById(@Param("userId") Long userId);

    @Select("SELECT COUNT(*) FROM users WHERE u_mobile = #{mobile}")
    int countByMobile(@Param("mobile") String mobile);

    // 新增：更新用户积分和剩余天数
    @Update("UPDATE users SET u_points = #{points}, u_rt = #{remainingDays}, updated_at = NOW() WHERE user_id = #{userId}")
    int updateUserInfo(@Param("userId") Long userId, @Param("points") Integer points, @Param("remainingDays") Integer remainingDays);
    
    // 新增：更新用户完整信息（支持昵称、手机号、密码）
    @Update("UPDATE users SET u_nickname = #{nickname}, u_mobile = #{mobile}, u_pw = #{password}, updated_at = NOW() WHERE user_id = #{userId}")
    int updateUserProfile(@Param("userId") Long userId, @Param("nickname") String nickname, @Param("mobile") String mobile, @Param("password") String password);
    
    // 新增：验证用户密码
    @Select("SELECT COUNT(*) FROM users WHERE user_id = #{userId} AND u_pw = #{password}")
    int verifyPassword(@Param("userId") Long userId, @Param("password") String password);
}